home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB5 Code / Class 6 / Exercise6.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-18  |  13.3 KB  |  464 lines

  1. VERSION 5.00
  2. Begin VB.Form frmPublishers 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Publishers"
  5.    ClientHeight    =   5580
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4650
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   5580
  13.    ScaleWidth      =   4650
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.TextBox txtInput 
  16.       DataField       =   "Comments"
  17.       DataSource      =   "datPublishers"
  18.       Height          =   285
  19.       Index           =   9
  20.       Left            =   1320
  21.       Locked          =   -1  'True
  22.       TabIndex        =   9
  23.       Text            =   "Text1"
  24.       Top             =   3360
  25.       Width           =   3255
  26.    End
  27.    Begin VB.TextBox txtInput 
  28.       DataField       =   "Fax"
  29.       DataSource      =   "datPublishers"
  30.       Height          =   285
  31.       Index           =   8
  32.       Left            =   1320
  33.       Locked          =   -1  'True
  34.       TabIndex        =   8
  35.       Text            =   "Text1"
  36.       Top             =   3000
  37.       Width           =   1575
  38.    End
  39.    Begin VB.TextBox txtInput 
  40.       DataField       =   "Telephone"
  41.       DataSource      =   "datPublishers"
  42.       Height          =   285
  43.       Index           =   7
  44.       Left            =   1320
  45.       Locked          =   -1  'True
  46.       TabIndex        =   7
  47.       Text            =   "Text1"
  48.       Top             =   2640
  49.       Width           =   1575
  50.    End
  51.    Begin VB.TextBox txtInput 
  52.       DataField       =   "Zip"
  53.       DataSource      =   "datPublishers"
  54.       Height          =   285
  55.       Index           =   6
  56.       Left            =   1320
  57.       Locked          =   -1  'True
  58.       TabIndex        =   6
  59.       Text            =   "Text1"
  60.       Top             =   2280
  61.       Width           =   1575
  62.    End
  63.    Begin VB.TextBox txtInput 
  64.       DataField       =   "State"
  65.       DataSource      =   "datPublishers"
  66.       Height          =   285
  67.       Index           =   5
  68.       Left            =   1320
  69.       Locked          =   -1  'True
  70.       TabIndex        =   5
  71.       Text            =   "Text1"
  72.       Top             =   1920
  73.       Width           =   1575
  74.    End
  75.    Begin VB.TextBox txtInput 
  76.       DataField       =   "City"
  77.       DataSource      =   "datPublishers"
  78.       Height          =   285
  79.       Index           =   4
  80.       Left            =   1320
  81.       Locked          =   -1  'True
  82.       TabIndex        =   4
  83.       Text            =   "Text1"
  84.       Top             =   1560
  85.       Width           =   3255
  86.    End
  87.    Begin VB.TextBox txtInput 
  88.       DataField       =   "Address"
  89.       DataSource      =   "datPublishers"
  90.       Height          =   285
  91.       Index           =   3
  92.       Left            =   1320
  93.       Locked          =   -1  'True
  94.       TabIndex        =   3
  95.       Text            =   "Text1"
  96.       Top             =   1200
  97.       Width           =   3255
  98.    End
  99.    Begin VB.TextBox txtInput 
  100.       DataField       =   "Company Name"
  101.       DataSource      =   "datPublishers"
  102.       Height          =   285
  103.       Index           =   2
  104.       Left            =   1320
  105.       Locked          =   -1  'True
  106.       TabIndex        =   2
  107.       Text            =   "Text1"
  108.       Top             =   840
  109.       Width           =   3255
  110.    End
  111.    Begin VB.TextBox txtInput 
  112.       DataField       =   "Name"
  113.       DataSource      =   "datPublishers"
  114.       Height          =   285
  115.       Index           =   1
  116.       Left            =   1320
  117.       Locked          =   -1  'True
  118.       TabIndex        =   1
  119.       Text            =   "Text1"
  120.       Top             =   480
  121.       Width           =   3255
  122.    End
  123.    Begin VB.CommandButton cmdHelp 
  124.       Caption         =   "&Help"
  125.       Height          =   375
  126.       Left            =   3240
  127.       TabIndex        =   19
  128.       TabStop         =   0   'False
  129.       Top             =   5160
  130.       Width           =   1215
  131.    End
  132.    Begin VB.Data datPublishers 
  133.       Caption         =   "Data1"
  134.       Connect         =   "Access"
  135.       DatabaseName    =   "C:\VBDB\Working\Biblio.mdb"
  136.       DefaultCursorType=   0  'DefaultCursor
  137.       DefaultType     =   2  'UseODBC
  138.       Exclusive       =   0   'False
  139.       Height          =   300
  140.       Left            =   2520
  141.       Options         =   0
  142.       ReadOnly        =   0   'False
  143.       RecordsetType   =   1  'Dynaset
  144.       RecordSource    =   "SELECT * FROM Publishers ORDER BY Name"
  145.       Top             =   120
  146.       Visible         =   0   'False
  147.       Width           =   1980
  148.    End
  149.    Begin VB.CommandButton cmdDone 
  150.       Caption         =   "Do&ne"
  151.       Height          =   375
  152.       Left            =   3240
  153.       TabIndex        =   18
  154.       TabStop         =   0   'False
  155.       Top             =   4680
  156.       Width           =   1215
  157.    End
  158.    Begin VB.CommandButton cmdDelete 
  159.       Caption         =   "&Delete"
  160.       Height          =   375
  161.       Left            =   1680
  162.       TabIndex        =   17
  163.       TabStop         =   0   'False
  164.       Top             =   4680
  165.       Width           =   1215
  166.    End
  167.    Begin VB.CommandButton cmdEdit 
  168.       Caption         =   "&Edit"
  169.       Height          =   375
  170.       Left            =   120
  171.       TabIndex        =   16
  172.       TabStop         =   0   'False
  173.       Top             =   4200
  174.       Width           =   1215
  175.    End
  176.    Begin VB.CommandButton cmdCancel 
  177.       Caption         =   "&Cancel"
  178.       Height          =   375
  179.       Left            =   3240
  180.       TabIndex        =   15
  181.       TabStop         =   0   'False
  182.       Top             =   4200
  183.       Width           =   1215
  184.    End
  185.    Begin VB.CommandButton cmdSave 
  186.       Caption         =   "&Save"
  187.       Height          =   375
  188.       Left            =   1680
  189.       TabIndex        =   14
  190.       TabStop         =   0   'False
  191.       Top             =   4200
  192.       Width           =   1215
  193.    End
  194.    Begin VB.CommandButton cmdAddNew 
  195.       Caption         =   "&Add New"
  196.       Height          =   375
  197.       Left            =   120
  198.       TabIndex        =   13
  199.       TabStop         =   0   'False
  200.       Top             =   4680
  201.       Width           =   1215
  202.    End
  203.    Begin VB.CommandButton cmdNext 
  204.       Caption         =   "Next =>"
  205.       Height          =   255
  206.       Left            =   2520
  207.       TabIndex        =   12
  208.       TabStop         =   0   'False
  209.       Top             =   3840
  210.       Width           =   1215
  211.    End
  212.    Begin VB.CommandButton cmdPrevious 
  213.       Caption         =   "<= Previous"
  214.       Height          =   255
  215.       Left            =   1080
  216.       TabIndex        =   11
  217.       TabStop         =   0   'False
  218.       Top             =   3840
  219.       Width           =   1215
  220.    End
  221.    Begin VB.TextBox txtInput 
  222.       DataField       =   "PubID"
  223.       DataSource      =   "datPublishers"
  224.       Height          =   285
  225.       Index           =   0
  226.       Left            =   1320
  227.       Locked          =   -1  'True
  228.       TabIndex        =   10
  229.       TabStop         =   0   'False
  230.       Text            =   "Text1"
  231.       Top             =   120
  232.       Width           =   1215
  233.    End
  234.    Begin VB.Label Label1 
  235.       Caption         =   "Comments"
  236.       Height          =   255
  237.       Index           =   9
  238.       Left            =   120
  239.       TabIndex        =   28
  240.       Top             =   3360
  241.       Width           =   1215
  242.    End
  243.    Begin VB.Label Label1 
  244.       Caption         =   "FAX"
  245.       Height          =   255
  246.       Index           =   8
  247.       Left            =   120
  248.       TabIndex        =   27
  249.       Top             =   3000
  250.       Width           =   1215
  251.    End
  252.    Begin VB.Label Label1 
  253.       Caption         =   "Telephone"
  254.       Height          =   255
  255.       Index           =   7
  256.       Left            =   120
  257.       TabIndex        =   26
  258.       Top             =   2640
  259.       Width           =   1215
  260.    End
  261.    Begin VB.Label Label1 
  262.       Caption         =   "Zip"
  263.       Height          =   255
  264.       Index           =   6
  265.       Left            =   120
  266.       TabIndex        =   25
  267.       Top             =   2280
  268.       Width           =   1215
  269.    End
  270.    Begin VB.Label Label1 
  271.       Caption         =   "State"
  272.       Height          =   255
  273.       Index           =   5
  274.       Left            =   120
  275.       TabIndex        =   24
  276.       Top             =   1920
  277.       Width           =   1215
  278.    End
  279.    Begin VB.Label Label1 
  280.       Caption         =   "City"
  281.       Height          =   255
  282.       Index           =   4
  283.       Left            =   120
  284.       TabIndex        =   23
  285.       Top             =   1560
  286.       Width           =   1215
  287.    End
  288.    Begin VB.Label Label1 
  289.       Caption         =   "Address"
  290.       Height          =   255
  291.       Index           =   3
  292.       Left            =   120
  293.       TabIndex        =   22
  294.       Top             =   1200
  295.       Width           =   1215
  296.    End
  297.    Begin VB.Label Label1 
  298.       Caption         =   "Company Name"
  299.       Height          =   255
  300.       Index           =   2
  301.       Left            =   120
  302.       TabIndex        =   21
  303.       Top             =   840
  304.       Width           =   1215
  305.    End
  306.    Begin VB.Label Label1 
  307.       Caption         =   "Name"
  308.       Height          =   255
  309.       Index           =   1
  310.       Left            =   120
  311.       TabIndex        =   20
  312.       Top             =   480
  313.       Width           =   1215
  314.    End
  315.    Begin VB.Label Label1 
  316.       Caption         =   "Publisher ID"
  317.       Height          =   255
  318.       Index           =   0
  319.       Left            =   120
  320.       TabIndex        =   0
  321.       Top             =   120
  322.       Width           =   1215
  323.    End
  324. Attribute VB_Name = "frmPublishers"
  325. Attribute VB_GlobalNameSpace = False
  326. Attribute VB_Creatable = False
  327. Attribute VB_PredeclaredId = True
  328. Attribute VB_Exposed = False
  329. Option Explicit
  330. Private Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
  331. Private Const HELP_FINDER = &HB&
  332. Private Sub ValidateData(AllOK As Boolean)
  333. Dim Message As String
  334. AllOK = True
  335. 'Check for name
  336. If Len(txtInput(1).Text) = 0 Then
  337.   Message = "You must enter a Publisher Name." & vbCrLf & Message
  338.   txtInput(1).SetFocus
  339.   AllOK = False
  340. End If
  341. If Not (AllOK) Then
  342.   MsgBox Message, vbOKOnly + vbInformation, "Validation Error"
  343. End If
  344. End Sub
  345. Private Sub cmdAddNew_Click()
  346. On Error GoTo HandleErrors
  347. Call SetState("Add")
  348. Exit Sub
  349. HandleErrors:
  350. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  351. Case vbAbort
  352.   Exit Sub
  353. Case vbRetry
  354.   Resume
  355. Case vbIgnore
  356.   Resume Next
  357. End Select
  358. End Sub
  359. Private Sub cmdCancel_Click()
  360. Call SetState("View")
  361. End Sub
  362. Private Sub cmdDelete_Click()
  363. Dim Response As Integer
  364. On Error GoTo HandleErrors
  365. Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete")
  366. If Response = vbNo Then
  367.   Exit Sub
  368. End If
  369. Exit Sub
  370. HandleErrors:
  371. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  372. Case vbAbort
  373.   Exit Sub
  374. Case vbRetry
  375.   Resume
  376. Case vbIgnore
  377.   Resume Next
  378. End Select
  379. End Sub
  380. Private Sub cmdEdit_Click()
  381. Call SetState("Edit")
  382. End Sub
  383. Private Sub cmdHelp_Click()
  384. Dim Rtn As Long
  385. Rtn = WinHelp(frmPublishers.hwnd, App.HelpFile, HELP_FINDER, CLng(0))
  386. End Sub
  387. Private Sub cmdNext_Click()
  388. datPublishers.Recordset.MoveNext
  389. If datPublishers.Recordset.EOF Then
  390.   Beep
  391.   datPublishers.Recordset.MoveLast
  392. End If
  393. End Sub
  394. Private Sub cmdPrevious_Click()
  395. datPublishers.Recordset.MovePrevious
  396. If datPublishers.Recordset.BOF Then
  397.   Beep
  398.   datPublishers.Recordset.MoveFirst
  399. End If
  400. End Sub
  401. Private Sub cmdSave_Click()
  402. Dim Valid As Boolean
  403. Call ValidateData(Valid)
  404. If Not (Valid) Then Exit Sub
  405. On Error GoTo HandleErrors
  406. MsgBox "Record saved.", vbOKOnly + vbInformation, "Save"
  407. Call SetState("View")
  408. Exit Sub
  409. HandleErrors:
  410. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  411. Case vbAbort
  412.   Exit Sub
  413. Case vbRetry
  414.   Resume
  415. Case vbIgnore
  416.   Resume Next
  417. End Select
  418. End Sub
  419. Private Sub SetState(AppState As String)
  420. Dim I As Integer
  421. Select Case AppState
  422. Case "View"
  423.   txtInput(0).BackColor = vbWhite
  424.   For I = 1 To 9
  425.     txtInput(I).Locked = True
  426.   Next I
  427.   cmdPrevious.Enabled = True
  428.   cmdNext.Enabled = True
  429.   cmdAddNew.Enabled = True
  430.   cmdSave.Enabled = False
  431.   cmdCancel.Enabled = False
  432.   cmdEdit.Enabled = True
  433.   cmdDelete.Enabled = True
  434.   cmdDone.Enabled = True
  435.   txtInput(1).SetFocus
  436. Case "Add", "Edit"
  437.   txtInput(0).BackColor = vbRed
  438.   For I = 1 To 9
  439.     txtInput(I).Locked = False
  440.   Next I
  441.   cmdPrevious.Enabled = False
  442.   cmdNext.Enabled = False
  443.   cmdAddNew.Enabled = False
  444.   cmdSave.Enabled = True
  445.   cmdCancel.Enabled = True
  446.   cmdEdit.Enabled = False
  447.   cmdDelete.Enabled = False
  448.   cmdDone.Enabled = False
  449.   txtInput(1).SetFocus
  450. End Select
  451. End Sub
  452. Private Sub Form_Activate()
  453. Call SetState("View")
  454. End Sub
  455. Private Sub txtInput_KeyPress(Index As Integer, KeyAscii As Integer)
  456. If KeyAscii = vbKeyReturn Then
  457.   If Index <> 9 Then
  458.     txtInput(Index + 1).SetFocus
  459.   Else
  460.     txtInput(1).SetFocus
  461.   End If
  462. End If
  463. End Sub
  464.